import { defineConfig, loadEnv } from 'vite'
import viteBaseConfig from "./config/vite.base.config";
import viteDevConfig from "./config/vite.dev.config";
import viteProdConfig from "./config/vite.prod.config";

const envResolver = {
  "build": (BASEURL: string) => ({ ...viteBaseConfig(BASEURL), ...viteProdConfig }),
  "serve": (BASEURL: string) => ({ ...viteBaseConfig(BASEURL), ...viteDevConfig })
}

export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), '')
  return envResolver[command](env.VITE_BASE_URL)
})